import { listMyUserSignVoByPageUsingPost } from '@/services/backend/userSignController';
import { PageContainer } from '@ant-design/pro-components';
import type { CalendarProps } from 'antd';
import { Calendar } from 'antd';
import type { Dayjs } from 'dayjs';
import React from 'react';
import { useRequest } from 'umi';
import dayjs from 'dayjs';

const SignRecord: React.FC = () => {
  const { data } = useRequest(() => {
    return listMyUserSignVoByPageUsingPost({});
  });

  const dateCellRender = (current: Dayjs) => {
    const signInDates = data?.records.map(record => dayjs(record.signTime).format('YYYY-MM-DD')) || [];
    const currentDate = current.format('YYYY-MM-DD');

    if (signInDates.includes(currentDate)) {
      return (
        <div style={{ justifyContent: 'center', textAlign: 'center' }}>
          ✔
        </div>
      );
    } else if (current.isBefore(dayjs())) {
      return (
        <div style={{ justifyContent: 'center', textAlign: 'center' }}>
          ❌
        </div>
      );
    }
    return null; // No indication for future dates
  };

  const cellRender: CalendarProps<Dayjs>['cellRender'] = (current, info) => {
    if (info.type === 'date') return dateCellRender(current);
    return info.originNode;
  };

  return (
    <PageContainer>
      <Calendar cellRender={cellRender} />
    </PageContainer>
  );
};

export default SignRecord;
